package com.tambapps.p2p.fandem.util

import java.io.File
import java.io.FileOutputStream
import java.io.IOException

fun interface FileProvider {
    @Throws(IOException::class)
    fun newFile(name: String): File
    fun toOutputStreamProvider(): OutputStreamProvider? {
        return OutputStreamProvider { fileName: String ->
            val outputFile = newFile(fileName)
            if (!outputFile.exists() && !outputFile.createNewFile()) {
                throw IOException("Couldn't create file $outputFile")
            }
            FileOutputStream(outputFile)
        }
    }
}
